package com.eedi.framework.user.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.user.controller.sys.vo.SysUserProfileEditPwdReq;
import com.eedi.framework.user.controller.sys.vo.SysUserProfileEditReq;
import com.eedi.framework.user.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.eedi.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import javax.annotation.Resource;

import static com.eedi.framework.common.pojo.CommonResult.success;

/**
 * 个人中心
 * @author zybourn
 */
@Tag(name = "系统界面 - 个人中心")
@RestController
@RequestMapping("/user/user-profile")
@Validated
public class SysProfileController {

    @Resource
    SysUserService sysUserService;

    @PostMapping("/edit-info")
    @Operation(summary = "修改个人信息")
    @PreAuthorize("@sys.hasPermission('sys:user:edit-info')")
    public CommonResult<Boolean> editInfo(@RequestBody SysUserProfileEditReq req) {
        sysUserService.editSysUserInfo(getLoginUserId(), req);
        return success(true);
    }

    @PostMapping("/edit-pwd")
    @Operation(summary = "修改密码")
    @PreAuthorize("@sys.hasPermission('sys:user:edit-pwd')")
    public CommonResult<Boolean> editPwd(@RequestBody SysUserProfileEditPwdReq req) {
        sysUserService.editPwd(getLoginUserId(), req);
        return success(true);
    }
}
